<template>
	<view class="container">
		<view class="avatarBox">
			<image @click="onChooseAvatar" class="avatar-wrapper"
				:src="userInfo.UserAvatarURL?userInfo.UserAvatarURL:userUrl" mode="aspectFit"></image>
			<view class="avatarTitle" @click="toEditUser('用户名',userInfo.UserName)">
				{{userInfo.UserName||''}}
			</view>
			<view class="avatarTitle" @click="toEditUserInfo('手机号变更',userInfo.UserPhone)">
				{{userInfo.UserPhone||''}}
			</view>
		</view>
		<view class="list">
			<view class="listItem" @click="toPage('/pages/limit/limit')">
				<image src="/static/user/wded.png" mode=""></image>
				<text class="text">我的额度</text>
				<uni-icons type="forward"></uni-icons>
			</view>
			<view class="listItem" @click="toEditUserInfo('手机号变更',userInfo.UserPhone)">
				<image src="/static/user/phone.png" mode=""></image>
				<text class="text">手机号变更</text>
				<uni-icons type="forward"></uni-icons>
			</view>
			<view class="listItem" @click="toPage('/pages/User/RealPage')">
				<image src="/static/user/wdrz.png" mode=""></image>
				<text class="text">我的认证</text>
				<uni-icons type="forward"></uni-icons>
			</view>
			<view class="listItem" @click="toPage('/pages/User/customerPage?Type=0')">
				<image src="/static/user/yinsi.png" mode=""></image>
				<text class="text">隐私政策</text>
				<uni-icons type="forward"></uni-icons>
			</view>
			<view class="listItem" @click="toPage('/pages/User/customerPage?Type=1')">
				<image src="/static/user/fwxy.png" mode=""></image>
				<text class="text">服务协议</text>
				<uni-icons type="forward"></uni-icons>
			</view>
			<view class="listItem" @click="toPage('/pages/User/setting')">
				<image src="/static/user/set.png" mode=""></image>
				<text class="text">设置</text>
				<uni-icons type="forward"></uni-icons>
			</view>
			<view class="listItem" @click="toPage('/pages/User/cancellation')">
				<image src="/static/user/zhuxiao.png" mode=""></image>
				<text class="text">注销账号</text>
				<uni-icons type="forward"></uni-icons>
			</view>
		</view>
	</view>
</template>

<script>
	const idCardPass = (text) => {
		if (text) {
			let a = text.split('')
			a.splice(6, 8, '********')
			return a.join('')
		} else {
			return '请认证身份证信息'
		}
	}
	export default {
		components: {},
		data() {
			return {
				userInfo: {},
				userUrl: 'https://hzq.yoojet.com/logo200.png',
				CompanyInfo: {},
				idCardPass,
			}
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url: '/pages/User/setting'
			})
		},
		onLoad() {

		},
		async onShow() {
			uni.removeStorageSync('ReceiptKeyword')
			// 获取用户信息
			await this.op()
			this.CommpayInfo = uni.getStorageSync('CompanyInfo')
			this.userInfo = uni.getStorageSync('userInfo')
			// 获取token
		},
		methods: {

			// // 获取TOKEN
			// async getToken() {
			// 	console.log('获取token', this.userInfo)
			// 	await uni.request({
			// 		url: this.$veriUrl + '/auth/VeriRecord/token?phone=' + this.userInfo.UserPhone,
			// 		method: 'GET'
			// 	}).then(result => {
			// 		let [err, res] = result;
			// 		if (res.data.code == 200) {
			// 			this.token = JSON.parse(res.data.data).access_token
			// 			console.log('获取的token', this.token, this.flag)
			// 		}
			// 	})
			// },
			// // 验证是否实名认证
			// async AuthRealName() {
			// 	console.log('获取实名认证', this.userInfo)
			// 	this.flag = false
			// 	await uni.request({
			// 		url: this.$veriUrl + '/auth/VeriRecord/state?Value=' + this.userInfo.UserPhone,
			// 		method: 'GET'
			// 	}).then(result => {
			// 		let [err, res] = result;
			// 		if (res.data.code == 200) {
			// 			console.log('获取的实名信息', this.token, this.flag)
			// 			this.flag = false

			// 			if (this.userInfo.name) this.getBG(this.userInfo.name)
			// 			else uni.removeStorageSync('nameBG')
			// 		} else {
			// 			this.flag = true
			// 		}
			// 		uni.setStorageSync('userInfo', this.userInfo)
			// 	})
			// 	return this.flag
			// },
			// getBG(name) {
			// 	this.$http('post', '/Base_Manage/Upload/GetNameSign?Name=' + name).then(res => {
			// 		if (res.Success) uni.setStorageSync('nameBG', res.Data)
			// 	})
			// },
			toPage(url, type) {
				if (type == 'menu') uni.switchTab({
					url
				})
				else uni.navigateTo({
					url
				})
			},
			async op() {
				await this.$http('post', '/Base_Manage/Home/GetOperatorInfo').then(res => {
					if (res.Success) {
						console.log('获取用户信息===', res.Data)
						// if(res.Data.UserInfo.BusinessLicense){
						// 	console.log('获取营业执照', res.Data.UserInfo.BusinessLicense)
						// 	this.fileList=[]
						// 	this.fileList.push(res.Data.UserInfo.BusinessLicense)
						// 	// 隐藏上传区域
						// 	this.uploadFlag=false
						// 	// 隐藏商铺认证按钮
						// 	this.isAuthentication=true
						// }
						uni.setStorageSync('userInfo', res.Data.UserInfo)

					}
				})
			},
			// 商铺认证
			toRealShop() {
				let obj = JSON.stringify(this.CompanyInfo)
				uni.navigateTo({
					url: '/pages/User/RealShop?CompanyInfo=' + obj
				})
			},
			toEditUser(type, name) {
				let url = ''
				if (type == '用户名') url =
					`type=text&value=${this.userInfo.UserName||''}&key=UserName&title=用户名&name=${this.userInfo.UserName}`
				else if (type == '手机号变更') url =
					`type=number&value=${this.userInfo.UserPhone||''}&key=UserPhone&title=手机号&Phone=${this.userInfo.UserPhone}`
				uni.navigateTo({
					url: '/pages/User/editUser?' + url
				})
			},
			// 修改个人信息
			toEditUserInfo(type, name) {
				let url = ''
				if (type == '用户名') url =
					`type=text&value=${this.userInfo.UserName||''}&key=UserName&title=用户名&name=${this.userInfo.UserName}`
				else if (type == '手机号变更') url =
					`type=number&value=${this.userInfo.UserPhone||''}&key=UserPhone&title=手机号&Phone=${this.userInfo.UserPhone}`
				uni.navigateTo({
					url: '/pages/User/editUserInfo?' + url
				})
			},
			// 用户头像
			onChooseAvatar(e) {
				uni.chooseImage({
					count: 1,
					sourceType: ['camera', 'album'],
					success: (rst) => {
						console.log(rst);
						uni.navigateTo({
							url: '/pages/User/camera?path=' + encodeURIComponent(rst
								.tempFilePaths[0])
						})
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		box-sizing: border-box;
		padding: 10px;

		.avatarBox {
			padding: 0 10px;
			display: flex;
			margin-bottom: 20rpx;
			height: 180px;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			background-image: url('/static/user/bg.png');
			/* #ifdef MP-WEIXIN */
			background-image: $UserBG;
			/* #endif */
			background-size: 100% 100%;
			color: #eee;
			font-family: '仿宋';
			font-size: 20px;

			.avatar-wrapper {
				background-color: transparent;
				width: 70px;
				height: 70px;
				padding: 0;
				border-radius: 50%;
				border: 1px solid #fff;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.avatarTitle {
				margin-top: 5px;
			}
		}

		.list {
			padding: 0 10px;

			.listItem {
				display: flex;
				align-items: center;
				background-color: #fff;
				padding: 12px 10px;
				border-radius: 10px;
				box-sizing: border-box;
				box-shadow: 0px 0px 3px #eee;
				margin-bottom: 8px;
				font-size: 14px;

				image {
					width: 25px;
					height: 25px;
				}

				.text {
					padding-left: 10px;
					flex: 1;
				}

				.uni-icons {
					font-weight: bold;
				}
			}
		}

	}
</style>